﻿$(document).ready(function() {
    $('.addCreator').each(function() {
        $(this).click(function() {
        var username = $(this).parent().siblings().first().text();
        $(this).siblings().css('visibility', 'visible');
            $.ajax({
                type: 'POST',
                url: "AddPollCreator",
                data: { pollID: $('#pollID').val(), UserName: username },
                success: function() {
                    window.location.href = "/Poll/Questions?pollID=" + $('#pollID').val() + "&pollName=" + $('#pollName').val();
                }
            });
        });
    });
    $('.addMaster').each(function() {
        $(this).click(function() {
            var username = $(this).parent().siblings().first().text();
            $(this).siblings().css('visibility', 'visible');
            $.ajax({
                type: 'POST',
                url: "AddPollMaster",
                data: { pollID: $('#pollID').val(), UserName: username },
                success: function() {
                    window.location.href = "/Poll/Questions?pollID=" + $('#pollID').val() + "&pollName=" + $('#pollName').val();
                }
            });
        });
    });
    $('#filter').keyup(function() {
        var filterValue = $(this).val().toLowerCase();
        if (filterValue == "") {
            $('.selectUserItem').each(function() {
                $(this).removeClass("none");
            });
        }
        else {
            $('.selectUserItem').each(function() {
                if ($(this).text().toLowerCase().indexOf(filterValue) < 0) {
                    $(this).addClass("none");
                }
                else {
                    $(this).removeClass("none");
                }
            });
        }
    });
    $('#filter').click(function() {
        $(this).val("");
        $(this).unbind('click');
    });
});